/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __AICPU_HCCL_SQCQV1_H__
#define __AICPU_HCCL_SQCQV1_H__

#include <memory>
#include <vector>

#include "ascend_hal.h"
#include "log.h"
#include "aicpu_hccl_sqcq.h"

#pragma pack(push)
#pragma pack(1)
struct rtStarsNotifySqeV1_t {
    rtStarsSqeHeader_t header;

    uint32_t notify_id : 13;
    uint32_t res2 : 19;

    uint16_t res3;
    uint8_t kernel_credit;
    uint8_t res4;
    uint32_t timeout;
    uint32_t res5[11];
};
#pragma pack(pop)

extern void TranslateOpcode(uint8_t opCode, uint8_t &reduceType);

extern void AddOneNotifyWaitSqeV1(uint16_t streamId, uint16_t taskId, u64 notifyId, const uint8_t *sqeIn,
    uint8_t *sqeType, const dfx::DfxTimeOutConfig &dfxTimeOutConfig);

extern void AddOneRecordSqeV1(uint16_t streamId, uint16_t taskId, u64 notifyId, const uint8_t *sqeIn, uint8_t *sqeType);

extern void AddOneWriteValueRecordSqeV1(uint16_t streamId, uint16_t taskId, u64 notifyWRAddr, const uint8_t *sqeIn,
    uint8_t *sqeType);

extern void AddOneMemcpySqeV1(uint16_t streamId, uint16_t taskId, const void *src, uint32_t length,
    const rtDataType_t rtDataType, rtRecudeKind_t rtReduceOp, const void *dst, uint32_t partId, uint32_t ssid,
    uint32_t devId, u64 overflowAddr, uint8_t linkType, const uint8_t *sqeIn, uint8_t *sqeType);

extern void AddOneRdmaDbSendSqeV1(uint16_t streamId, uint16_t taskId, uint64_t dbInfo, uint64_t dbAddr,
    uint32_t length, uint8_t rdmaType, const uint8_t *sqeIn, uint8_t *sqeType);

extern void AddOneEventResetSqeV1(uint16_t streamId, int32_t eventId, uint16_t taskId, int64_t phyChipId,
    int64_t phyDieId, u64 eventAddr, const uint8_t *sqeIn, uint8_t *sqeType);

extern void AddOneEventRecordSqeV1(uint16_t streamId, int32_t eventId, uint16_t taskId, const uint8_t *sqeIn,
    uint8_t *sqeType);

extern void AddOneEventWaitSqeV1(uint16_t streamId, int32_t eventId, uint16_t taskId, const uint8_t *sqeIn,
    uint8_t *sqeType);

extern void AddOneFlipPlaceHolderSqeV1(uint16_t streamId, uint16_t flipNum, uint16_t taskId, const uint8_t *sqeIn,
    uint8_t *sqeType);

// 分别返回硬件和软件的超时时长，二者一般只有一个值是有效的
std::pair<uint64_t, uint64_t> GetTimeOutValue(const dfx::DfxTimeOutConfig &dfxTimeOutConfig);
#endif // __AICPU_HCCL_SQCQV1_HPP__